﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Noria.Web.MyMSDN.Models;

namespace Noria.Web.Utility
{
    /// <summary>
    /// Summary description for archive
    /// </summary>
    public class Archive : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string payload = null;

            using (var db = new MmContext())
            {
                var data = db.Files.Where(p => p.eMule != null).Select(p => new
                    {
                        p.eMule,
                        p.Sha1,
                        p.Size,
                        p.FileName
                    });

                payload = JArray.FromObject(data).ToString(Formatting.None);
            }

            context.Response.ContentType = "application/json";
            context.Response.Write(payload);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}